package com.cool.modules.erp.service.impl;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.cool.core.base.BaseServiceImpl;
import com.cool.core.util.TenantUtil;
import com.cool.modules.erp.entity.ErpSupplierInfoEntity;
import com.cool.modules.erp.mapper.ErpSupplierInfoMapper;
import com.cool.modules.erp.service.ErpSupplierInfoService;
import org.springframework.stereotype.Service;

/**
 * 供应商信息
 */
@Service
public class ErpSupplierInfoServiceImpl extends BaseServiceImpl<ErpSupplierInfoMapper, ErpSupplierInfoEntity> implements ErpSupplierInfoService {

    @Override
    public Long add(ErpSupplierInfoEntity entity) {
        Long tenantId = TenantUtil.getTenantId();
        String tenantIdStr = tenantId == null ? "000000" : StrUtil.padAfter(tenantId.toString(), 6, '0');
        // 供应商编号：GYS + 租户ID（填充6位） + 随机字符串(6位)
        String code = StrUtil.format("GYS" + tenantIdStr + RandomUtil.randomNumbers(6));
        entity.setCode(code);
        entity.setTenantId(tenantId);
        return super.add(entity);
    }
}